﻿using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Reflection;
using Abp.Modules;
using Abp.Zero.EntityFramework;
using SingleUserMall.EntityFramework;

namespace SingleUserMall
{
    [DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(SingleUserMallCoreModule))]
    public class SingleUserMallDataModule : AbpModule
    {
        public override void PreInitialize()
        {
            //Database.SetInitializer(new CreateDatabaseIfNotExists<SingleUserMallDbContext>());
            //自动迁移
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<SingleUserMallDbContext, Migrations.Configuration>());
            var dbMigrator = new DbMigrator(new Migrations.Configuration());
            dbMigrator.Update();
            Configuration.DefaultNameOrConnectionString = "Default";
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}
